//
// gcs_session.h
// gcs
// Grand Central Station, controlling process of the Protea Application Server / manages user sessions
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#ifndef __PROTEA_GCS_SESSION_H__
#define __PROTEA_GCS_SESSION_H__

#include <time.h>

class GCSSession {
public:
	GCSSession( char* username, int s_id );

	void Reset( time_t& timeout, int last_trans, int app_number );
	bool CheckTimeOut( time_t& timeout );

	const char* GetUser() const { return user; };
	int GetID() const { return id; };
	int GetLastTrans() const { return trans_number; };
	int GetLastApp() const { return app_number; };

	GCSSession* next;
	GCSSession* prev;

private:
	char* user;
	int id;
	int trans_number;
	int app_number;
	time_t timeout;
};



class GCSSessionsList {
public:
	GCSSessionsList();

	const int Count();

	bool Refresh( time_t& current_time );

	GCSSession* GetSession( char* username, int& session_id, int trans_number, int app );
	void RemoveSession( char* username, int session_id );

	const GCSSession* GetFirstSession();

	XCCriticalSection session_lock;

private:
	int count;
	GCSSession* sessionlist;
};

#endif
